package cn.com.xf.common;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.util.Properties;

/**
 * 读取conifg.properties
 * 
 * @author fangjinsong
 * 
 */
public class ConfigUtil {
	private static URL filePath = Thread.currentThread().getContextClassLoader().getResource("");
	private static String fileName = "config.properties";

	public ConfigUtil() {
	}

	private static Properties props = new Properties();

	static {
		try {
			String path = filePath.getPath();
			// 将classes/删掉
			// path = path.substring(0,path.length()-8) + fileName;
			props.load(new FileInputStream(path + "config" + File.separator + fileName));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static String getValue(String key) {
		return props.getProperty(key);
	}

	public static void updateProperties(String key, String value) {
		props.setProperty(key, value);
	}
}